<?php
/**
 * SocialEngine
 *
 * @category   Application_Core
 * @package    Credit
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Transaction.php 7244 2012-01-23 01:49:53Z taalay $
 * @author     Taalay
 */

/**
 * @category   Application_Core
 * @package    Credit
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */
 
class Credit_Plugin_Payment_Transaction extends Engine_Payment_Transaction
{
  // Constants

  // General
  const ACTION_TYPE = 'actionType';                // The transaction type
  const CURRENCY_CODE = 'currencyCode';        // The currency of the transaction
  const FEES_PAYER = 'feesPayer';        // The payer of PayPal fees. Allowable values are
  const MEMO = 'memo';        // The note associated with the payment (text, not HTML). The maximum is 1,000 characters. You can use new line characters.
  
  // URLs
  const RETURN_URL = 'returnUrl';    // URL to return to on success
  const CANCEL_URL = 'cancelUrl';    // URL to return to on failure
  const IPN_URL = 'ipnNotificationUrl';          // URL to send IPN to

  // Receiver List
  const PRIMARY_RECEIVER_EMAIL = 'receiverList.receiver[0].email'; //The email address of the primary receiver of the payment.
  const SECONDARY_RECEIVER_EMAIL = 'receiverList.receiver[1].email'; //The email address of the secondary receiver of the payment.

  const PRIMARY_RECEIVER_AMOUNT = 'receiverList.receiver[0].amount'; //The amount information of primary receiver of the payment.
  const SECONDARY_RECEIVER_AMOUNT = 'receiverList.receiver[1].amount'; //The amount information of secondary receiver of the of the payment.

  const PRIMARY_RECEIVER_PRIMARY = 'receiverList.receiver[0].primary'; //The primary information of primary receiver of the payment.
  const SECONDARY_RECEIVER_PRIMARY = 'receiverList.receiver[1].primary'; //The primary information of secondary receiver of the payment.
  
  const PRIMARY_RECEIVER_PAYMENT_TYPE = 'receiverList.receiver[0].paymentType'; //The primary information of primary receiver of the payment.
  const SECONDARY_RECEIVER_PAYMENT_TYPE = 'receiverList.receiver[1].paymentType'; //The primary information of secondary receiver of the payment.

  //Client Details
  const SENDER_EMAIL = 'senderEmail'; //The email address of sender of the payment;
  const CLIENT_DEVICE_ID = "clientDetails.deviceId";
	const CLIENT_IP_ADDRESS ="clientDetails.ipAddress";
	const CLIENT_APPLICATION_ID = "clientDetails.applicationId";

  // Request Envelope
  const REQUEST_ENVELOPE_ERROR_LANGUAGE = "requestEnvelope.errorLanguage"; //The information common to each Method, such as the language in which an error message is returned

  // Pay Key
  const PAY_KEY = "payKey"; // The transaction key

  // Tracking ID
  const TRACKING_ID = 'trackingId'; //The unique ID that you specify to track the payment.


  
  public function process(Engine_Payment_Gateway $gateway)
  {
    if( null !== $this->_driver && $this->_driver !== $gateway->getDriver() ) {
      throw new Engine_Payment_Exception('Already processed, cannot process with a different driver');
    }
    $this->_driver = $gateway->getDriver();

    /**
     * @var $gateway Credit_Plugin_Payment_Gateway_PayPal | Credit_Plugin_Payment_Gateway_2Checkout
     */
    $data = $gateway->processTransaction($this);

    $this->_isProcessed = true;
    if( is_array($data) ) {
      $this->_isValid = true;
      $this->_data = $data;
    } else {
      $this->_isValid = false;
      $this->_data = null;
    }

    return $this;
  }
}